<?php
/**
 * @version		$Id: invoice.php 3 2011-12-16 20:19:15Z netix.mail@gmail.com $
 * @package		ALM Hoster
 * @desription	Web hosting and domain menager for resellers
 * @subpackage	Components
 * @copyright	Copyright (C) 2011 ALM Studio. All rights reserved.
 * @author		ALM Studio
 * @email		info@alm-studio.net
 * @link		http://alm-studio.net
 * @license		Commercial
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.modelitem');

class AlmHosterModelInvoice extends JModelItem
{
	
	
protected function populateState()
	{
		$app = JFactory::getApplication('site');
		
		$pk = JRequest::getInt('InvoiceId');
		$this->setState('invoice.InvoiceId', $pk);

	}
	
	public function &getItem($pk = null)
	{
		$pk = (!empty($pk)) ? $pk : (int) $this->getState('invoice.InvoiceId');
			
		if (!isset($this->_item))
		{
			$db		= $this->getDbo();
			$query	= $db->getQuery(true);
			$query->select(
			'a.InvoiceId, a.InvoiceOrder, a.InvoiceDate, a.InvoiceDue,'. 
			'a.InvoiceProduct, a.InvoiceAmount, a.InvoiceStatus'						
			);
			$query->from('#__almh_invoices AS a');	
			$query->where('a.InvoiceId = ' . (int) $pk);
			
			$query->select('c.ClientName AS client');
			$query->join('LEFT', '#__almh_clients AS c ON c.ClientId = a.InvoiceClient');
		
								
			$db->setQuery((string) $query);

				if (!$db->query()) {
					JError::raiseError(500, $db->getErrorMsg());
				}
				$this->_item = $db->loadObject();
			}
		return $this->_item;
	}
}